package com.tpl.core.basedata.action.sys;

import java.util.List;

import com.tpl.core.action.BaseAction;
import com.tpl.core.basedata.service.DictMenuService;
import com.tpl.core.common.DateUtil;
import com.tpl.core.common.ValidateUtil;
import com.tpl.core.common.page.Page;
import com.tpl.core.entity.sys.DictMenu;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 说明 :数据字典目录视图层
 * @author 
 * @version
 *
 */
@Controller
@RequestMapping("/dictMenu")
public class DictMenuAction extends BaseAction {
	private static final long serialVersionUID = 8829152766356510616L;
	
	@Autowired
	private DictMenuService dictMenuService;
	@RequestMapping("/toDicMenutManager.do")
	public String toDicMenutManager(){
		
		return "dict/dictMenuManager";
	}
	@RequestMapping("/toDicMenutList.do")
	public String getDataDictList(String key,String kname){
		Page page=dictMenuService.getDictMenus(key,kname,getPageIndex(), getPageSize());
		List<DictMenu> menus=dictMenuService.getDictMenuList(new DictMenu());
		putInRequest("page", page,"key",key,"kname",kname,"menus",menus);
		return "dict/dictMenuList";
	}
	
	@RequestMapping("/toEditDictMenu.do")
	public String getDictMenuById(Long dmId){
		if(null!=dmId){
			DictMenu dictMenu=dictMenuService.getDictMenuById(dmId);
			putInRequest("dictMenu", dictMenu);
		}
			return "dict/dictMenuEdit";
	}
	
	/**
	 * 字典目录保存
	 * @param dictMenu
	 * @return 
	 * @return 
	 */
	@RequestMapping("/saveOrUpdateDictMenu.do")
	public  @ResponseBody void doSaveOrUpdate(DictMenu dictMenu){
			ValidateUtil.validLength(dictMenu.getName(), 2, 20, "名称");
			dictMenu.setUpdateDate(DateUtil.now());
			dictMenu.setUpdator(getLoginUser().getUserNo());
			dictMenuService.saveOrUpdateDictMenu(dictMenu);
			outJsonSuccess();
	}
	/**
	 * 字典目录删除
	 * @return
	 */
	@RequestMapping("/toDelDictMenu.do")
	public @ResponseBody void doDeleteOst(Long dmId){
		ValidateUtil.validRequired(dmId, "字典目录信息");
			dictMenuService.deleteDictMenu(dmId);
			outJsonSuccess();
	}
	
}
